# -*- coding: utf-8 -*-
from dingtalkchatbot.chatbot import DingtalkChatbot
from sqlalchemy import false


class DingTalkLogic(object):
    def __init__(self, webhook, secret) -> None:
        self.sendHandle = DingtalkChatbot(webhook, secret)

    def sendMsg(self, params):
        msg_type = params['msg_type'] if "msg_type" in params else 1
        if msg_type == 1:
            alls = params['is_at_all'] if "is_at_all" in params else false
            msg = params['msg']
            mobiles = params['at_mobiles'] if "at_mobiles" in params else []
            result = self.sendHandle.send_text(msg, is_at_all=alls, at_mobiles=mobiles)
        if msg_type == 2:
            title = params['title']
            msg = params['msg']
            msg_url = params['msg_url']
            result = self.sendHandle.send_link(title, msg, msg_url)
        return result

